package com.czy.booktest02.demos.api.v1;

import com.czy.booktest02.demos.common.dtos.ResponseResult;
import com.czy.booktest02.demos.pojo.dto.BookFileDto;
import com.czy.booktest02.demos.service.BookFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/file")
public class FileController {

    @Autowired
    BookFileService bookFileService;

    /**
     * 文件上传
     *
     * @param file
     * @param request
     * @return
     */
    @PostMapping("/uploadIamge")
    public ResponseResult uploadPicture(@RequestBody BookFileDto bookFileDto, @RequestParam("file") MultipartFile file, HttpServletRequest request) {
        return bookFileService.uploadPicture(bookFileDto,file,request);
    }

    /**
     * 查询文件记录
     */
    @PostMapping("/selectFileRecord")
    public ResponseResult selectFileRecord(@RequestParam("bookName") String bookName){
        return bookFileService.selectFileRecord(bookName);
    }
    /**
     * 删除文件记录
     */
    @PostMapping("/deleteFileRecord")
    public ResponseResult deleteFileRecord(String bookName){
        return bookFileService.deleteFileRecord(bookName);
    }
    /**
     * 显示文件记录
     */
    @GetMapping("/showFileRecord")
    public ResponseResult showFileRecord(){
        return bookFileService.showFileRecord();
    }
}
